package com.pet.taglib;

import java.io.IOException;

import javax.servlet.jsp.JspException;

import org.apache.struts2.views.jsp.StrutsBodyTagSupport;
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;

import com.pet.framework.util.SpringUtil;
import com.pet.role.util.Logger;
import com.pet.server.bo.role.RoleService;
import com.pet.server.po.Constant;

public class ParseCode extends StrutsBodyTagSupport{
	private static final Logger logger = Logger.getLogger(ParseCode.class);
	private Object code;
	private String type;
	@Override
	public int doEndTag() throws JspException{
		return EVAL_PAGE;
		
	}
	
	@Override
	public int doStartTag() throws JspException {
	   RoleService roleService=(RoleService) SpringUtil.getBean("roleService");
	   Constant constant=roleService.findConstantByCode(code.toString());
	   
	   try {
		   if(constant!=null){
			pageContext.getOut().write(constant.getContsName());
		   }
		} catch (IOException e) {
			logger.logError("parse code error:"+e.getMessage());
		}
		return EVAL_BODY_BUFFERED;
	}

	public Object getCode() {
		return code;
	}

	public void setCode(Object code) throws JspException {
		this.code = ExpressionEvaluatorManager.evaluate(
	            "code", code.toString(), Object.class, this, pageContext); 
	}

	public static Logger getLogger() {
		return logger;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	
}
